home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / gfx / lise2.1 / lise / src / str / getline.c next >
Encoding:
C/C++ Source or Header  |  1993-03-31  |  740 b   |  37 lines

  1. /* read specified line from file */
  2. #include <stdio.h>
  3.  
  4. main(argc,argv)
  5. int argc;
  6. char *argv[];
  7. {
  8. char c,s[256];
  9. int i,n,m;
  10. FILE *fp;
  11.  
  12.    if(argc!=3) { /* print help message */
  13.       printf("getline file number\nreturns the line specified from the file\n");
  14.       printf("\n(C) Rainer Kowallik\n");
  15.       exit(0);
  16.    }
  17.    n=atoi(argv[2]);
  18.    fp=fopen(argv[1],"r");
  19.    if(fp==NULL) { /* trap file open error */
  20.       fprintf(stderr,"can not open file %s\n",argv[1]);
  21.       exit(-1);
  22.    }
  23.    for(m=0;m<n;m++) {
  24.       fgets(s,256,fp); /* read whole string from file */
  25.       if(feof(fp)) { /* trap end of file */
  26.          printf("EOF\n");
  27.          fclose(fp);
  28.          exit(1);
  29.       }
  30.    }
  31.    fclose(fp);
  32.    printf("%s\n",s);
  33.    exit(0);
  34. }
  35.  
  36.  
  37.